/*!
 * \file	graphics.c
 * \brief	Definitions of graphics-related functions for Qong.
 * \author	Jon "delrio" Cox
 * \date	February 1, 2011
 */

//------------------------------------------------------------------------//
//  Qong                                                                  //
//  Copyright (C) 2011 Jon Cox                                            //
//                                                                        //
//  This program is free software: you can redistribute it and/or modify  //
//  it under the terms of the GNU General Public License as published by  //
//  the Free Software Foundation, either version 3 of the License, or     //
//  (at your option) any later version.                                   //
//                                                                        //
//  This program is distributed in the hope that it will be useful,       //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of        //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
//  GNU General Public License for more details.                          //
//                                                                        //
//  You should have received a copy of the GNU General Public License     //
//  along with this program.  If not, see <http://www.gnu.org/licenses/>. //
//------------------------------------------------------------------------//

#include <stdlib.h>
#include <types.h>
#include <misc.h>
#include <graphics.h>
#include <defines.h>
#include <SDL.h>
#include <SDL_opengl.h>

/*!
 * \brief Initializes SDL video for a screen.
 *
 * \param screen SDL surface to initialize.
 * \param flags Video mode flags to pass to SetVideoMode.
 * \return False if operation failed, true if success.
 *
 * Please note that a lot of this code was taken from the SDL initialization
 * tutorial on gpwiki.
 * Link: http://gpwiki.org/index.php/SDL:Tutorials:Initializing_SDL_Libraries
 */
int initVideo( SDL_Surface *screen, Uint32 flags )
{
	if ( flags == 0 )
	{
		flags = SDL_DOUBLEBUF | SDL_OPENGL;
	}

	// Load SDL
	if ( SDL_Init( SDL_INIT_VIDEO ) )
	{
		ERROR( true, "Unable to initialize SDL." );
		return false;
	}

	// Get ready for some OpenGL action.
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	// Set up SDL video stuff
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 16, flags );
	if ( screen == NULL )
	{
		ERROR( true, "Unable to set video mode." );
		return false;
	}

	// Some window settings.
	SDL_WM_SetCaption( "Qong", "Qong" );

	return true;
}
